#ifndef _IRQFLAGS_H_
#define _IRQFLAGS_H_
#include <printf.h>
/*
 * Save the current interrupt enable state & disable IRQs
 */
static inline unsigned long arch_local_irq_save(void)
{
    unsigned long flags, temp;

    asm volatile(
        "	mrs	%0, cpsr	@ arch_local_irq_save\n"
        "	orr	%1, %0, #128\n"
        "	msr	cpsr_c, %1"
        : "=r"(flags), "=r"(temp)
        :
        : "memory", "cc");
#if 0

    if (flags & 128)
        vprintk("interrupt disabled context, old flags: 0x%x, new flags: 0x%x\n", flags, temp);
    else
        vprintk("interrupt enable context, old flags: 0x%x, new flags: 0x%x\n", flags, temp);

#endif
    return flags;
}

/*
 * Enable IRQs
 */
static inline void arch_local_irq_enable(void)
{
    unsigned long temp;
    asm volatile(
        "	mrs	%0, cpsr	@ arch_local_irq_enable\n"
        "	bic	%0, %0, #128\n"
        "	msr	cpsr_c, %0"
        : "=r"(temp)
        :
        : "memory", "cc");
}

/*
 * Disable IRQs
 */
static inline void arch_local_irq_disable(void)
{
    unsigned long temp;
    asm volatile(
        "	mrs	%0, cpsr	@ arch_local_irq_disable\n"
        "	orr	%0, %0, #128\n"
        "	msr	cpsr_c, %0"
        : "=r"(temp)
        :
        : "memory", "cc");
}
/*
 * restore saved IRQ & FIQ state
 */
static inline void arch_local_irq_restore(unsigned long flags)
{
    asm volatile(
        "	msr	cpsr_c, %0	@ local_irq_restore"
        :
        : "r"(flags)
        : "memory", "cc");
}
#endif /* ifndef __ASM_ARM_IRQFLAGS_H */
